package com.stream;

import java.util.*;
import java.util.stream.Collectors;

class Girl{
    int id;
    String ass;
    public Girl(int id,String ass){
        this.id = id;
        this.ass = ass;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAss() {
        return ass;
    }

    public void setAss(String ass) {
        this.ass = ass;
    }

    @Override
    public String toString() {
        return "Girl{" +
                "id=" + id +
                ", ass='" + ass + '\'' +
                '}';
    }
}
class Boy{
    int id;
    String jiji;
    public Boy(int id,String jiji){
        this.id = id;
        this.jiji = jiji;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getJiji() {
        return jiji;
    }

    public void setJiji(String jiji) {
        this.jiji = jiji;
    }

    @Override
    public String toString() {
        return "Boy{" +
                "id=" + id +
                ", jiji='" + jiji + '\'' +
                '}';
    }
}


public class 合并集合 {
    public static void merge(){
        List<Boy> b1 = new ArrayList<Boy>();
       Collections.addAll(b1,new Boy(1,"18cm"),new Boy(2,"20cm"));
       List<Girl> g1 = new ArrayList<>();
       Collections.addAll(g1,new Girl(1,"50cm"),new Girl(2,"50cm"));
       Collections.disjoint(b1,g1);
        b1.forEach(System.out::print);
        System.out.println(" ");
        g1.forEach(System.out::print);





    }
    public static void each(){
        List<String> list = Arrays.asList("one","two","three","four","one","two");
       list.forEach(System.out::print);
        System.out.println("");
        System.out.println("============");
        list.forEach(str->{
            System.out.print(str+"要fuck you,");
        });
        System.out.println("");
        System.out.println("============");
        list.stream().forEach(str->{
            System.out.print(str+"吃jj,");
        });
        System.out.println("");
        System.out.println("============");
       List<String> l2 =  list.stream().map(map->map+"操bb,").collect(Collectors.toList());
       l2.forEach(System.out::print);
        System.out.println("");
        System.out.println("======去重======");
       List<String> l3= list.stream().distinct().collect(Collectors.toList());
        l3.forEach(System.out::print);
        System.out.println("");
        System.out.println("======limit======");
       List<String> l4 =  list.stream().limit(2).collect(Collectors.toList());
       l4.forEach(System.out::print);
       List<Integer> nums = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
        System.out.println("");
        System.out.println("======统计======");
       IntSummaryStatistics summary =  nums.stream().mapToInt(m->m).summaryStatistics();
        System.out.println(String.format("和：%s,平均:%s,最大：%s,最小:%s,数量：%s",summary.getSum(),summary.getAverage(),summary.getMax(),summary.getMin(),summary.getCount()));


    }

    public static List<Map<Object, Object>> compareListHitData(List<Map<Object, Object>> oneList, List<Map<Object, Object>> twoList) {
        List<Map<Object, Object>> resultList = oneList.stream().map(map -> twoList.stream()
                .filter(m -> Objects.equals(m.get("id"), map.get("id")))
                .findFirst().map(m -> {
                    map.putAll(m);
                    return map;
                }).orElse(null))
                .filter(Objects::nonNull).collect(Collectors.toList());
        return resultList;
    }
    public static void main(String[] args) {
        merge();
//        each();
//        Girl gi
//        rl = new Girl(1,"100cm");
//        Boy boy = new Boy(1,"18cm");
//        List<Girl> l1 = new ArrayList<>();
//        l1.add(girl);
//
//        List<Boy> l2 =new ArrayList<>();
//        l2.add(boy);
//       Map<Object,Object> map1 = l1.stream().collect(Collectors.toMap(Girl::getId,girl1 -> girl1));
//       Map<Object,Object> map2 = l2.stream().collect(Collectors.toMap(Boy::getId,boy1 -> boy1));
//        List<Map<Object, Object>> l3 = new ArrayList<>();
//        l3.add(map1);
//        List<Map<Object,Object>> l4 = new ArrayList<>();
//        l4.add(map2);
//       List l5 = compareListHitData(l3,l4);
//        System.out.println(l5);


//        List<Map<Object, Object>> oneList = new ArrayList<>();
//        Map<Object, Object> oneMap = new HashMap<>();
//        oneMap.put("id", 111);
//        oneMap.put("userName", "何金荣");
//        Map<Object, Object> twoMap = new HashMap<>();
//        twoMap.put("id", 222);
//        twoMap.put("userName", "Hejinrong");
//        oneList.add(oneMap);
//        oneList.add(twoMap);
//        List<Map<Object, Object>> twoList = new ArrayList<>();
//        Map<Object, Object> threeMap = new HashMap<>();
//        threeMap.put("id", 111);
//        threeMap.put("userName", "何金荣");
//        Map<Object, Object> fourMap = new HashMap<>();
//        fourMap.put("id", 333);
//        fourMap.put("userName", "Hejinrong");
//        twoList.add(threeMap);
//        twoList.add(fourMap);
//        List<Map<Object, Object>> resultList = compareListHitData(oneList, twoList);
//        System.out.println(resultList);

    }
}
